function u = memberships(x, y, num, k1)
% x:nxm,y:nx1,k1是一个常数,u:n*num,这个num代表类别
n = size(x, 1);
u = zeros(n, num);
for i = 1 : n
    ind = [1 : i - 1, i + 1 : n];
    Dist = sum((x(ind, :) - x(i, :)).^2,2);
    % 从小大大排序，取前k1个
    [~,I] = sort(Dist);
    D_y = y(I(1:k1), :);
    for j = 1 : num
        nj = sum(D_y == j);
        if y(i, :) == j
            u(i, j) = 0.51 + (nj / k1) * 0.49;
        else
            u(i, j) = (nj / k1) * 0.49;
        end
    end
end
end